// List.h
#ifndef __LIST_H__
#define __LIST_H__

#include <algorithm>
#include <list>

#include "util/Container.h"
#include "util/Pool.h"

template <typename T>
class List : public std::list <T, pool_allocator<T> >, public Container<T> {
 public:
    NEW_DELETE_OPERATORS_INLINE_H(List<T>,NoSuper);
    
    List () {};
    virtual ~List () {};

    // add puts a new item into the queue
    void add (T t) { push_back(t); }

    void push (T t) { push_front(t); }
    
    T pop () {
        T t = *this->begin();
        this->pop_front();
        return t;
    }

    // peek looks at the head of the queue/stack without removing it
    T peek () const { return *this->begin(); }

    // remove takes an item from the queue
    T remove () { return pop(); }

    T find (T t) const {
        typename List<T>::const_iterator i = std::find(this->begin(), this->end(), t);
        if (i == this->end()) {
            return (T)NULL;
        }
        return t;
    }

    bool contains (T t) {
        typename List<T>::iterator i = std::find(this->begin(), this->end(), t);
        if (i == this->end()) {
            return false;
        }
        return true;
    }

    T remove (T t) {
        typename List<T>::iterator i = std::find(this->begin(), this->end(), t);
        if (i == this->end()) {
            return (T)NULL;
        }
        erase(i);
        return t;
    }

    T containerRemove (T t) {
        return remove(t);
    }

    // length allows the caller to determine how full the queue in
    // question currently is . . . .
    int getLength () const { 
        return this->size(); 
    }
};

#endif // __LIST_H__
